<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
	<meta charset="utf-8" />
		<title>箱型管理</title>		
		
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/locale/ext-lang-zh_CN.js"></script>
			<link rel="stylesheet" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css" />
			
			
</head>
<body>
<div id="selForm"></div>
<div id="find"></div>
<div id="boxTypeManage"></div>
</body>
<script type="text/javascript">
Ext.onReady(function(){
	Ext.QuickTips.init();
	var selModel = Ext.create('Ext.selection.CheckboxModel',{checkOnly:false});
	  var columns = [ 
					{text:'ID',dataIndex:'ID',hidden:true},
	                 {text:'箱型缩写',dataIndex:'BOX_TYPE_ABBREVIATION'}, //sortable:true 可设置是否为该列进行排序  
	                 {text:'箱型名称',dataIndex:'BOX_TYPE_NAME'},
	                 {text:'空箱重量',dataIndex:'EMPTY_BOX_WEIGHT'},  
	                 {text:'类别代码',dataIndex:'TYPE_CODE'},  
	                 {text:'是否可用',dataIndex:'ENABLE'}, 
	                 {text:'检索码',dataIndex:'FAST_SEARCH_CODE'},  
	                 {text:'排序代码',dataIndex:'SORT_CODE'},  
	               ]; 

	  Ext.define('store', {
			extend : 'Ext.data.Model',
			fields :[  
				   {
	   		name:'ID'
	   	},  {
	   	    name: 'BOX_TYPE_ABBREVIATION'
	   	},{
	   	    name : 'BOX_TYPE_NAME'
	   	},{
	   	    name : 'EMPTY_BOX_WEIGHT'
	   	},{
	   	    name : 'TYPE_CODE'
	   	},{
	   	    name : 'ENABLE'
	   	},{
	   	    name : 'FAST_SEARCH_CODE'
	   	},{
	   	    name : 'SORT_CODE'
	   	}		]
		});
	  var store = Ext.create('Ext.data.Store', {
			model : 'store',
			pageSize:10,
//			pageSize : thePageSize,
			id:'store',
			proxy : {
				type : 'ajax',
				actionMethods : {
					read : 'POST'
				},//将提交方式改为post
				url : '<%=basePath%>boxTypeManage/value',
				reader : {
					type : 'json',
					root: 'result.list',  //数据
	                totalProperty: 'result.total' //数据总条数
				}
			}
		});
	  store.load({ params:{start : 0,limit : 10}}); 
 		  var paging = new Ext.PagingToolbar(
					{
						store : store,
						 pageSize:10,
						displayInfo : true,
						displayMsg : '<span style="color:blue;">第{0}条</span>至<span style="color:blue;">{1}条</span>，共<span style="color:blue;">{2}</span>条记录',
						emptyMsg : '无记录'
					}); 

			var tradeTypeStore = Ext.create('Ext.data.Store', {
				fields: ['id', 'name'],
				data : [
					{"id":"", "name":"请选择"},
					{"id":"1", "name":"是"},
					{"id":"0", "name":"否"}
				]
			});
	  var c1 = Ext.create('Ext.container.Container', {
			layout: 'column',
			defaults: { labelAlign: 'left', labelWidth: 60 },
			items: [
				{id:"startDate1",xtype: 'textfield', name: 'startDate1',padding: '5px',fieldLabel: '快速检索码'},
				{id:"startDate2",xtype: 'textfield', name: 'startDate2', padding: '5px', fieldLabel: '箱型缩写'},
				{id:"startDate3",xtype: 'combobox',  name: 'startDate3',value:'',editable: false,displayField: 'name', queryMode: 'local',store:tradeTypeStore,valueField: 'id',padding: '5px', fieldLabel: '是否可用'},
				{id:"startDate4",xtype: 'textfield', name: 'startDate4', padding: '5px', fieldLabel: '箱型名称'},

			]
		});
	  var bs = Ext.create('Ext.container.Container', {
			layout: 'column',
			defaults: { labelAlign: 'left', labelWidth: 60 },
			items: [
				{id:"startDate5",xtype: 'textfield', name: 'startDate5',padding: '5px',fieldLabel: '类别代码'},
				{id:"startDate6",xtype: 'textfield', name: 'startDate6',padding: '5px',fieldLabel: '排序代码',regex: /^\d+$/,
					regexText: "排序代码只能为数字"},
				{id:"startDate7",xtype: 'textfield', name: 'startDate7',padding: '5px',fieldLabel: '空箱重量',regex: /^\d+$/,
	        		 	regexText: "空箱重量只能为数字",
			        		},
				{layout : 'column',baseCls : 'my-panel-no-border',  padding: '5px',  items: [
					{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "添加",handler: function(){
			      		 var FAST_SEARCH_CODE = Ext.getCmp('startDate1').getValue();
				      		var BOX_TYPE_ABBREVIATION = Ext.getCmp('startDate2').getValue();
				      		var ENABLE = Ext.getCmp('startDate3').getValue();
				      		var BOX_TYPE_NAME = Ext.getCmp('startDate4').getValue();
				      		var TYPE_CODE = Ext.getCmp('startDate5').getValue();
				      		var SORT_CODE = Ext.getCmp('startDate6').getValue();
				      		var EMPTY_BOX_WEIGHT = Ext.getCmp('startDate7').getValue();
		

				      		var ID = "";
				      		 Ext.Ajax.request({
				       			 url: '<%=basePath%>boxTypeManage/saveOrUpdate',
				        			 params:{ID:ID,FAST_SEARCH_CODE:FAST_SEARCH_CODE,BOX_TYPE_ABBREVIATION:BOX_TYPE_ABBREVIATION,ENABLE:ENABLE,BOX_TYPE_NAME:BOX_TYPE_NAME,TYPE_CODE:TYPE_CODE,SORT_CODE:SORT_CODE,EMPTY_BOX_WEIGHT:EMPTY_BOX_WEIGHT},
				        			 method: 'POST',
				        			success: function () {
				                       Ext.MessageBox.alert("保存成功","保存成功");
// 				                       var grid = Ext.getCmp('grid');
										Ext.getCmp("startDate1").setValue(null); 
										Ext.getCmp("startDate2").setValue(null); 
										Ext.getCmp("startDate3").setValue(null); 
										Ext.getCmp("startDate4").setValue(null); 
										Ext.getCmp("startDate5").setValue(null); 
										Ext.getCmp("startDate6").setValue(null); 
										Ext.getCmp("startDate7").setValue(null);  
										
				   					 grid.store.reload();
				                   },
				        		 });
				      	 } },
				],},
			]
		});
	  var c2 = Ext.create('Ext.container.Container', {
			layout: 'column',
			defaults: { labelAlign: 'left', labelWidth: 60 },
			items: [
				
				{id:"startDate8",xtype: 'textfield', name: 'startDate8', columnWidth:  1/5,padding: '5px', fieldLabel: '箱型缩写'},
				{id:"startDate9",xtype: 'textfield', name: 'startDate9',columnWidth: 1/5,padding: '5px',fieldLabel: '箱型名称'},

			]
		});
	  var bs2 = Ext.create('Ext.container.Container', {
			layout: 'column',
			items: [
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,   padding: '10px'},
				{layout : 'column',baseCls : 'my-panel-no-border',columnWidth: 1/5,  padding: '10px',  items: [
					{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "查询",handler: function(){
			      		 var BOX_TYPE_ABBREVIATION = Ext.getCmp('startDate8').getValue();
				      		var BOX_TYPE_NAME = Ext.getCmp('startDate9').getValue();
					var store = Ext.getCmp('grid').getStore();
					store.on('beforeload', function(store,options) {  
				            var new_params = {  
				            		BOX_TYPE_ABBREVIATION : BOX_TYPE_ABBREVIATION, BOX_TYPE_NAME:BOX_TYPE_NAME
				            };  
					//这里apply一下实现新的proxy  
				            Ext.apply(store.proxy.extraParams,new_params);  
				        });  
					//对store重新载入  
				        store.load();  


							
				      	 } },
				],},
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,  padding: '10px'}
			]
		});
	  var selForm = Ext.create('Ext.form.Panel', {
			title:'箱型管理',
			name: 'selForm',
			renderTo: "selForm",
			width:'100%',
//			collapsed :true,
			height:140,
//			collapsible:true,
			bodyStyle: {
				padding: '5px',
				border: 1
			},
			fieldDefaults: {
				labelAlign: 'left'
			},
			items: [c1,bs]
		});
	  var find = Ext.create('Ext.form.Panel', {
			
			name: 'find',
			renderTo: "find",
//			collapsed :true,
			height:70,
//			collapsible:true,
//			bodyStyle: {
//				padding: '5px',
//				border: 1
//			},
//			fieldDefaults: {
//				labelAlign: 'left'
//			},
			items: [c2,bs2]
		});
	  
	  var edit =new Ext.Button({
			text: '修改',
	     	listeners: {
	         'click': function () {
	        	 var records = grid.getSelectionModel().getSelection();
	        	 if(records.length==0){
		       			Ext.Msg.alert("提示","请选择需要编辑的实体记录");return;
		       		}
		       		if(records.length>1){
		       			Ext.Msg.alert("提示","只能编辑一条实体记录");return;
		       		}

		       		var win = Ext.create("Ext.window.Window", {
		 				title: "编辑",
		 				modal:true,
		 				width: 800,
		 				height: 180,
		 				maximizable: true,
		 				closeAction:'destroy',
		 				layout: "fit",
//		  				margin: '3 3 0',
		 		        buttonAlign:'center',
		 				items: [ 
		 				        	{
		 				        		xtype: "form",
		 				        		id:'form',
		 				        		bodyPadding: 5,
		 				        		layout: "hbox",
		 				        		defaults: {
		 				        			border: false,
		 				        			flex: 1,
		 				        			anchor: '100%'
		 				        		},
		 				        		fieldDefaults: {
		 				        			labelWidth: 92,
		 				        			labelAlign: "right",
		 				        			//flex: 1,
		 				        			margin: 5,
		 				        			labelStyle: 'color:green;'
		 				        		},
		 				        		items: [{
														columnWidth:.33,    
														layout: "form",
														items:[
		 				       					        	{
		 				       					        		xtype: 'textfield',
		 				       					        		name: 'ID',
		 				       					        		hidden: true, 
		 				       					        		hideLabel:true,
		 				       					        		fieldLabel: 'ID',
		 				       					        		value:records[0].data.ID,
		 				       					        		allowBlank:false
		 				       					        	},{
		 				       					        		xtype: 'textfield',
		 				       					        		name: 'BOX_TYPE_ABBREVIATION',
		 				       					        		fieldLabel: '箱型缩写',
		 				       					        		value:records[0].data.BOX_TYPE_ABBREVIATION,
		 				       					        		allowBlank:false
		 				       					        	},{
		 				       					        		xtype: 'textfield',
		 				       					        		name: 'FAST_SEARCH_CODE',
		 				       					        		fieldLabel: '快速检索码',
		 				       					        		value:records[0].data.FAST_SEARCH_CODE,
		 				       					        		allowBlank:false
		 				       					        	},{
		 				       					        		xtype:'combo',
		 				       					        		store:{
		 				       					        			fields:['use_flag','use_display'],
		 				       					        			data:[{use_flag:'1',use_display:'是'},{use_flag:'0',use_display:'否'}]
		 				       					        		},
		 				       					        		valueField:'use_flag',
		 				       					        		displayField:'use_display',
		 				       					        		allowBlank:false,
		 				       					        		name:'useFlag',
		 				       					        		fieldLabel:'是否可用',
		 				       					        		editable:false,
		 				       					        		value:records[0].data.ENABLE
		 				       					        	},{
		 				       					        		xtype: 'textfield',
		 				       					        		name: 'BOX_TYPE_NAME',
		 				       					        		fieldLabel: '箱型名称',
		 				       					        		value:records[0].data.BOX_TYPE_NAME,
		 				       					        		allowBlank:false
		 				       					        	}
		 				       					        	]},
		 				       					        	{
		 				       					        	columnWidth:.33,    
		 													layout: "form",
		 													 items:[
		 				       					        		{
		 				       					        		xtype: 'textfield',
		 				       					        		name: 'TYPE_CODE',
		 				       					        		fieldLabel: '类别代码',
		 				       					        		value:records[0].data.TYPE_CODE,
		 				       					        		allowBlank:false
		 				       					        	},{
		 				       					        		xtype: 'textfield',
		 				       					        		name: 'SORT_CODE',
		 				       					        		fieldLabel: '排序代码',
		 				       					        		regex: /^\d+$/,
             		       					        		 	regexText: "排序代码只能为数字",
		 				       					        		value:records[0].data.SORT_CODE,
		 				       					        		allowBlank:false
		 				       					        	},{
		 				       					        		xtype: 'textfield',
		 				       					        		name: 'EMPTY_BOX_WEIGHT',
		 				       					        		fieldLabel: '空箱重量',
			 				       					        	regex: /^\d+$/,
	         		       					        		 	regexText: "空箱重量只能为数字",
		 				       					        		value:records[0].data.EMPTY_BOX_WEIGHT,
		 				       					        		allowBlank:false
		 				       					        	}
		 				       					        	]}
		 				       					]
		 				        	}
		 				        ],
		 				       buttons: [{
   		       		            text: '保存',
   		       		            handler: function(){
   		       		            	var form = Ext.getCmp('form').getForm();
   							 if(form.isValid()){
   		       		            	form.submit({
   		       		            		params:{
   		       		            		ENABLE:form.findField('useFlag').value,
   		       		            		
   		       		            			
   		       		            		},
   		       		            		waitTitle : '请稍后...',  
   		       		            		waitMsg : '正在保存信息,请稍后...',  
   		       		            		url:'<%=basePath%>boxTypeManage/saveOrUpdate',
					          				success:function(form,action){
					          					Ext.Msg.alert("提示","保存成功");
					          					store.load();
					          					win.close();
					          				},

					          			});
   		       		            }else{
   		       		          		Ext.Msg.alert("提示","排序代码请输入数字");
   		       		            }
   		       		            }
   		       		        },{
   		       		            text: '关闭',
   		       		            handler: function(){
   		       		            	win.close();
   		       		            }
   		       		        }]
		 			});
		       		win.show();
	        }
	     }
		});
		var deleteInfo =new Ext.Button({
			text: '删除',
			handler:function(){
	     		var records = grid.getSelectionModel().getSelection();
	       			if(records.length==0){
	       				Ext.Msg.alert("提示","请选中需要删除的实体记录");return;
	       			}
	       			var arr = [];
	       			Ext.each(records,function(item){
	       				obj = {
	       						id:item.data.ID
	       				};
	       				arr.push(obj);
	       			});
	       			var array = JSON.stringify(arr);
	       			Ext.Msg.confirm("提示","确定删除数据?",function(btn){
		       				
		       					Ext.Ajax.request({
		       						url:'<%=basePath%>boxTypeManage/deleteInfo',
		       						params:{
		       							array:array
		       						},
		       						timeout:5000,
		       						success:function(response){
		       							store.load();
		       							Ext.Msg.alert("成功","删除成功!");
		       						},
		       						failure:function(response){
		       							Ext.Msg.alert("错误","请求异常!");
		       						}
		       					});
		       				
		       			});
	     	}
		});
		var grid = new Ext.grid.GridPanel({
			//collapsible :true,
		    //split: true,
		  renderTo:'boxTypeManage',
		    width:'50%',
		    store:store,
		    //forceFit:false,
		    columns:columns,
		    id:'grid',
		    selModel:selModel,
		    columnLines: true,
		    menuDisabled:true,
		    tbar: [edit,deleteInfo],
		     bbar : paging,
		    viewConfig:{enableTextSelection:true,stripeRows: true},
	
		});
});

</script>
</html>